﻿@using Entidades.Sistema.Base
@using System.Collections.ObjectModel;

@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "gvEditing";
            settings.KeyFieldName = "IdEmpleado";
            settings.CallbackRouteValues = new { Controller = "Empleado", Action = "EditEmpleadosPartial" };
            settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Empleado", Action = "EditEmpleadosAddNewPartial" };
            settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Empleado", Action = "EditEmpleadosUpdatePartial" };
            settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Empleado", Action = "EditEmpleadosDeletePartial" };
            settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;

            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };


            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;

            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowNewButtonInHeader = ViewBag.PermisoCreate;
            settings.CommandColumn.ShowEditButton = ViewBag.PermisoEdit;
            settings.CommandColumn.ShowDeleteButton = ViewBag.PermisoDelete;

            settings.Columns.Add("NombreApellido");


           //settings.Columns.Add("IdUsuario");
           settings.Columns.Add(
           column =>
           {
               column.FieldName = "IdUsuario";
               column.Caption = "IdUsuario";
               column.ReadOnly = true;
           });  
            
            
            settings.Columns.Add("Clave").Visible = false;
            
            ////TODO
            //settings.Columns.Add(
            //   column =>
            //   {
            //       column.FieldName = "Clave";
            //       column.Caption = "Clave";
            //       column.ReadOnly = true;
            //       column.EditFormSettings.Visible = DefaultBoolean.False;
            //       column.ColumnType = MVCxGridViewColumnType.TextBox;                   
            //       var tbSettings = column.PropertiesEdit as TextBoxProperties;
            //       tbSettings.Password = true;

            //   });
            
            settings.Columns.Add("Email");

            settings.Columns.Add(
                 column =>
                 {
                     column.FieldName = "Estado";
                     column.Caption = "Estado";

                     column.ColumnType = MVCxGridViewColumnType.CheckBox;
                     var CheckBoxProperties = column.PropertiesEdit as CheckBoxProperties;
                     CheckBoxProperties.ValueType = typeof(Boolean);
                 });    
            
            
            settings.Columns.Add(
                column =>
                {
                    column.FieldName = "Cargo.IdCargo";
                    column.Caption = "Cargo";

                    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                    comboBoxProperties.DataSource = ViewBag.Cargo;
                    comboBoxProperties.TextField = "Nombre";
                    comboBoxProperties.ValueField = "IdCargo";
                    comboBoxProperties.ValueType = typeof(int);
                    comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
                    comboBoxProperties.ValidationSettings.CausesValidation = false;
                });
            
        });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()




